﻿using System;
using FairyGUI;

/// <summary>
/// 通用提示框
/// </summary>
public class UICommon_TipWindow : UIPopupWindow {

	public UICommon_TipWindow(string message, Action closed)
    {
        // 加载界面
        base.Init(UIPackage.CreateObject("通用组件", "通用提示组件").asCom);

        // 初始化关闭按钮
        GButton closeBtn = uiComp.GetChild("关闭按钮").asButton;
        closeBtn.onClick.Add(() => {
            _Close();
			if (closed != null) {
				closed();
			}
        });

		GTextField msgText = uiComp.GetChild ("提示文字").asTextField;
		msgText.text = message;
    }

    void _Close()
    {
		DebugInfo.Log("关闭 通用提示");

        AudioController.inst.PlayUIClickEffect();
        uiComp.RemoveFromParent();
        uiComp.Dispose();
        base.Close();
    }

    /// <summary>
    /// 弹出窗口
    /// </summary>
	public static void Popup(string message, Action closed = null)
    {
        DebugInfo.Log("打开 通用提示");
		UIRootController.inst.PopupWindow(new UICommon_TipWindow(message, closed));
    }
}
